package com.jiangds.open.check.checker;

import com.jiangds.open.check.Checker;
import com.jiangds.open.pattern.PatternFactory;
import java.util.regex.Pattern;

/**
 * {@link StringChecker}  字符串类型校验
 *
 * @author jiangliang
 * @since 2021/1/5 13:57
 */
public class StringChecker extends AbstractChecker<Integer,String> {

    public StringChecker(String target) {
        super(target);
    }

    @Override
    public Checker<Integer,String> notEmpty() {
        notNull();
        return processor(t->!"".equals(t.trim()));
    }

    @Override
    public Checker<Integer,String> range(Integer min, Integer max) {
        return processor(t->t.length() <= max && t.length() >= min);
    }

    @Override
    public Checker<Integer, String> greater(String greaterThan) {
        return processor(t->t.compareTo(greaterThan)>=0);
    }

    @Override
    public Checker<Integer, String> less(String lessThan) {
        return processor(t-> t.compareTo(lessThan)<=0);
    }

    @Override
    public Checker<Integer, String> in(String... args) {
        return inProcessor(String::equals,args);
    }
}
